<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>hello</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="jquery.js" type="text/javascript"></script>
</head>
<body>
<!--/*@thymesVar id="name" type="java.lang.String"*/-->
<div>
    <button type="button" onclick="postAnswer()">提交答案</button>
    <input type="text" hidden="hidden" id="userPhysique"/>
</div>
<p id="physiqueBackdata"></p>

<button type="button" onclick="test()">test</button>

<script th:inline="javascript">
    /*<![CDATA[*/
    var basePath = location.href;
    function postAnswer(){
        var answers = [];
        for(var i=1;i<67;i++){
            var a = {
                optionKey:Math.ceil(Math.random()*5),
                questionId:i
            }
            answers.push(a);
        }
        var data = {
            userId:'18868193735',
            questionnaireId:'2',
            nums:'66',
            answers:answers
        };

        $.ajax({
            async: true,
            type: "post",
            url: basePath + "/answers?token=11111",
            data: JSON.stringify(data),
            contentType: "application/json;charset=UTF-8",
            success: function(data) {
                $("#physiqueBackdata").text(JSON.stringify(data));
                console.log(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.responseText);
            }
        });
    }
    function test(){
        $.ajax({
            async: true,
            type: "get",
            url: basePath + "/type",
            data: {type:2,userId:'18868193735'},
            contentType: "application/json",
            success: function(data) {
                $("#physiqueBackdata").text(JSON.stringify(data));
                console.log(data);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.responseText);
            }
        });
    }
    /*]]>*/
</script>
</body>
</html>